<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="css/login.css">
<!--  <link rel="shortcut icon" href="<%=basePath%>icon/arc_128.ico" type="image/x-icon" />-->
<title>autotools</title>
</head>
<body>

	<section class="container">
	<div class="login">
		<h1>用户登录</h1>

		<p>
			<input type="text" id="userName" name="username" value="" placeholder="用户名">
		</p>
		<p>
			<input type="password" id="pwd" name="pwd" value="" placeholder="密码">
		</p>
		<p>
                    <td>线路：</td><select id="lineID">
			</select>
		</p>
		<p class="remember_me">
			<label> <input type="checkbox" name="remember_me"
				id="remember_me"> 记住密码
			</label>
		</p>
		<p class="submit">
			<input type="button" name="commit" value="登录" onclick="dologin()">
		</p>

	</div>
<!--  
	<div class="login-help">
		<p>
			忘记密码? <a href="error.jsp">点击修改</a>.
		</p>
	</div>
	-->
	</section>
	<div style="text-align: center;">
	</div>
<script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/common.js"> </script>
<script type="text/javascript" src="<%=basePath%>js/md5.js"></script>
<script type="text/javascript">
$(function(){
	$(document).keydown(function(event){
		if(event.keyCode == 13)
		{
			dologin(); 
		}
	});
        fillLineID();
        

})

function fillLineID()
{
    sendAjaxRequest('<%=basePath%>getLineID', null,null, function(data){
            var jsonObj = data.data;
            if("success" ==  jsonObj.type){
                    $.each(jsonObj.data,function(i,obj)
                    {
                            $("#lineID").append("<option value='"+obj+"'>"+obj+"</option>");
                    })
            }
    })
}

function dologin(){
        var timestamp=new Date().getTime();
        var token = timestamp + Math.random();
	var json={"userName":$("#userName").val(),"password":hex_md5($("#pwd").val()),"lineID":$("#lineID").val(),"token":token};
	$.ajax({
		type : "POST",
		url : "<%=basePath%>dologin.action",
		data : json,
		dataType : "json",
		cache : false,
		async : false,
		error:function(XMLResponse){alert(XMLResponse.responseText)},
		success : function(result) {
				if (result.type == "error") {
					alert(result.message);
				} else {
					document.location = "<%=basePath%>main.action";
				}
			}
		});
}

</script>
</body>
</html>